package main

import (
	"fmt"
)

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func preorderTraversal(root *TreeNode, c chan int) {
	if root == nil {
		return
	}
	preorderTraversal(root.Left, c)
	select {
	case c <- root.Val:
	}
	preorderTraversal(root.Right, c)
}

func isValidBST(root *TreeNode) bool {
	c := make(chan int)
	r := true
	go func() {
		preorderTraversal(root, c)
		close(c)
	}()
	v, i := <-c
	if !i {
		return true
	}
	for {
		a, i := <-c
		if !i {
			break
		}
		fmt.Println("a:", a, v)
		if v >= a {
			r = false
			return r
		}
		v = a
	}
	return r
}

func main() {
	//fmt.Println(kkkkkk)
	//b := TreeNode{Val: 1}
	//t1 := TreeNode{Val: 1}
	//t2 := TreeNode{Val: 3, Left: &b, Right: &t1}
	t2 := TreeNode{Val: -1 << 31}
	//t3 := TreeNode{Val:5}
	//t4 := TreeNode{Val:10,Left:&t3,Right:&t2}

	//b := TreeNode{Val:1}
	//t1 := TreeNode{Val:1,Left:&b}
	c := isValidBST(&t2)
	fmt.Println(c)
}
